#!/bin/bash
mkdir -p demo-base/src/main/java
echo "build ..."
rm -rf output/*
mkdir -p output

if [ "ci" = $1 ] ; then
    mvn clean compile -pl demo-base,demo-bundle -am -Dbdgc.skip=false
elif [ "ut" = $1 ] ; then
    mvn clean verify -pl demo-jacoco-report -am -Put -Dbdgc.skip=false
elif [ "package_admin" = $1 ] ; then
    cd demo-admin
    npm install
    npm run build:prod
    tar -czf dist.tar.gz ./dist
    cp dist.tar.gz ../output
    cd ..
elif [ "docker_admin" = $1 ] ; then
    cd demo-admin
    npm install
    npm run build:prod
    cp -r dist ../output
    cp Dockerfile nginx.conf ../output
    cd ../output
    docker build . -t fastjrun/demo-admin:3.0.0
    cd ..
elif [ "package_server" = $1 ] ; then
    mvn clean package -pl demo-server -am -Dbdgc.skip=false
    cp demo-server/target/demo-server.jar ./output
elif [ "docker_server" = $1 ] ; then
    mvn clean package -pl demo-server -am -Dbdgc.skip=false
    cp demo-server/target/demo-server.jar ./output
    cp demo-server/Dockerfile ./output
    cd output
    docker build . -t fastjrun/demo-server:3.0
    cd ..
elif [ "package_mock_server" = $1 ] ; then
    mvn clean package -pl demo-mock-server -am -Dbdmgc.skip=false
    cp demo-mock-server/target/demo-mock-server.jar ./output
elif [ "clean_all" = $1 ] ; then
    mvn clean
    rm -rf output
    rm -rf demo-bundle/src
    rm -rf demo-bundle-mock/src
fi
echo "build done."
